package com.rondo.CurrencyFramework.controller;

import com.rondo.CurrencyFramework.domain.User;
import com.rondo.CurrencyFramework.serviceImpl.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.print.DocFlavor;
import javax.servlet.http.HttpServletRequest;

@Controller
public class HomeController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserServiceImpl userService;

    @GetMapping(value = "index")
    public ModelAndView index(){
        ModelAndView view = new ModelAndView();
        logger.trace("日志输出 trace");
        logger.debug("日志输出 debug");
        logger.info("日志输出 info");
        logger.warn("日志输出 warn");
        logger.error("日志输出 error");

        view.setViewName("index");
        // 设置属性
        view.addObject("title", "我的第一个WEB页面");
        view.addObject("desc", "欢迎进入battcn-web 系统");

        User user = new User();
        user.setId(1);
        user.setName("北海亦北");

        view.addObject("user", user);
        return view;
    }

    @GetMapping(value = "login")
    public String login(HttpServletRequest request){
        request.setAttribute("userlist", userService.getUserList());
        return "login";
    }
}
